/**
 * 
 */
package com.flying.dcss.dcauthorization.service.impl;

import java.util.Date;
import java.util.List;

import javax.faces.application.Application;

import com.flying.dcss.dcauthorization.bo.impl.DcssApplicationOrder;
import com.flying.dcss.dcauthorization.bo.impl.DcssPermissionOrder;
import com.flying.dcss.dcauthorization.dao.impl.DcssApplicationOrderDAO;
import com.flying.dcss.dcauthorization.dao.impl.DcssPermissionOrderDAO;
import com.flying.dcss.dcauthorization.service.IAuthorizeService;

// TODO: Auto-generated Javadoc
/**
 * The Class AuthorizeService.
 * 
 * @author EvanHong
 */
public class AuthorizeService implements IAuthorizeService {

	/** The application order dao. */
	private DcssApplicationOrderDAO applicationOrderDAO;

	/** The permission order dao. */
	private DcssPermissionOrderDAO permissionOrderDAO;

	/**
	 * Gets the application order dao.
	 * 
	 * @return the application order dao
	 */
	public DcssApplicationOrderDAO getApplicationOrderDAO() {

		return applicationOrderDAO;
	}

	/**
	 * Sets the application order dao.
	 * 
	 * @param applicationOrderDAO
	 *            the new application order dao
	 */
	public void setApplicationOrderDAO(
			DcssApplicationOrderDAO applicationOrderDAO) {
		this.applicationOrderDAO = applicationOrderDAO;
	}

	/**
	 * Gets the permission order dao.
	 * 
	 * @return the permission order dao
	 */
	public DcssPermissionOrderDAO getPermissionOrderDAO() {

		return permissionOrderDAO;
	}

	/**
	 * Sets the permission order dao.
	 * 
	 * @param permissionOrderDAO
	 *            the new permission order dao
	 */
	public void setPermissionOrderDAO(DcssPermissionOrderDAO permissionOrderDAO) {
		this.permissionOrderDAO = permissionOrderDAO;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.flying.dcss.dcauthorization.service.IAuthorizeService#addApplicationOrder
	 * (com.flying.dcss.dcauthorization.bo.impl.DcssApplicationOrder)
	 */
	public void addApplicationOrder(DcssApplicationOrder applicationOrder) {
		// TODO Auto-generated method stub
		applicationOrderDAO.save(applicationOrder);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.flying.dcss.dcauthorization.service.IAuthorizeService#addPermissionOrder
	 * (com.flying.dcss.dcauthorization.bo.impl.DcssPermissionOrder, int)
	 */
	public void addPermissionOrder(DcssPermissionOrder permissionOrder) {
		// TODO Auto-generated method stub
		permissionOrderDAO.save(permissionOrder);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @seecom.flying.dcss.dcauthorization.service.IAuthorizeService#
	 * getApplicationOrderByApproverId(java.lang.String, int)
	 */
	public List<DcssApplicationOrder> getApplicationOrderByApproverId(
			String approverId, int type) {
		// TODO Auto-generated method stub
		return applicationOrderDAO.findByApprover(approverId, type);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @seecom.flying.dcss.dcauthorization.service.IAuthorizeService#
	 * getApplicationOrderByDcId(java.lang.String, int)
	 */
	public List<DcssApplicationOrder> getApplicationOrderByDcId(String dcId,
			int type) {
		// TODO Auto-generated method stub
		return applicationOrderDAO.findByDCId(dcId, type);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @seecom.flying.dcss.dcauthorization.service.IAuthorizeService#
	 * getApplicationOrderByTime(java.util.Date, java.util.Date, int)
	 */
	public List<DcssApplicationOrder> getApplicationOrderByTime(Date startTime,
			Date endTime, int type) {
		// TODO Auto-generated method stub
		return applicationOrderDAO.findByTime(startTime, endTime, type);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @seecom.flying.dcss.dcauthorization.service.IAuthorizeService#
	 * getApplicationOrderByUserId(java.lang.String, int)
	 */
	public List<DcssApplicationOrder> getApplicationOrderByUserId(
			String userId, int type) {
		// TODO Auto-generated method stub
		return applicationOrderDAO.findByUserId(userId, type);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @seecom.flying.dcss.dcauthorization.service.IAuthorizeService#
	 * getPermissionOrderByApproverId(java.lang.String, int)
	 */
	public List<DcssPermissionOrder> getPermissionOrderByApproverId(
			String approverId, int type) {
		// TODO Auto-generated method stub
		return permissionOrderDAO.findByApprover(approverId, type);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @seecom.flying.dcss.dcauthorization.service.IAuthorizeService#
	 * getPermissionOrderByDcId(java.lang.String, int)
	 */
	public List<DcssPermissionOrder> getPermissionOrderByDcId(String dcId,
			int type) {
		// TODO Auto-generated method stub
		return permissionOrderDAO.findByDCId(dcId, type);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @seecom.flying.dcss.dcauthorization.service.IAuthorizeService#
	 * getPermissionOrderByTime(java.util.Date, java.util.Date, int)
	 */
	public List<DcssPermissionOrder> getPermissionOrderByTime(Date startTime,
			Date endTime, int type) {
		// TODO Auto-generated method stub
		return permissionOrderDAO.findByTime(startTime, endTime, type);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @seecom.flying.dcss.dcauthorization.service.IAuthorizeService#
	 * getPermissionOrderByUserId(java.lang.String)
	 */
	public List<DcssPermissionOrder> getPermissionOrderByUserId(String userId,
			int type) {
		// TODO Auto-generated method stub
		return permissionOrderDAO.findByUserId(userId, type);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @seecom.flying.dcss.dcauthorization.service.IAuthorizeService#
	 * getApplicationOrderById(java.lang.String)
	 */
	public DcssApplicationOrder getApplicationOrderById(String id) {
		// TODO Auto-generated method stub
		return applicationOrderDAO.findById(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @seecom.flying.dcss.dcauthorization.service.IAuthorizeService#
	 * getPermissionOrderById(java.lang.String)
	 */
	public DcssPermissionOrder getPermissionOrderById(String id) {
		// TODO Auto-generated method stub
		return permissionOrderDAO.findById(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @seecom.flying.dcss.dcauthorization.service.IAuthorizeService#
	 * passApplicationOrder()
	 */
	public void passApplicationOrder(String orderId) {
		// TODO Auto-generated method stub
		DcssApplicationOrder order = applicationOrderDAO.findById(orderId);
		order.setState(2);
		applicationOrderDAO.update(order);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @seecom.flying.dcss.dcauthorization.service.IAuthorizeService#
	 * rejectionApplicationOrder()
	 */
	public void rejectionApplicationOrder(String orderId) {
		// TODO Auto-generated method stub
		DcssApplicationOrder order = applicationOrderDAO.findById(orderId);
		order.setState(1);
		applicationOrderDAO.update(order);
	}

}
